<?php
require_once("../../../config.inc.php");
$isReloadable = true;
require_once("../../../app/_inc/include.php");
require_once("../_inc/procFunction.php");

$errMsg = "";
if(isset($_REQUEST["reqtype"])){	
	if($_REQUEST["reqtype"] == "save"){	
		$errMsg .= puLinkMod();
	}elseif($_REQUEST["reqtype"] == "delete"){
		$errMsg .= puLinkDel();
	}
	$process_unit = sxREQUEST("process_unit");
	$name = sxREQUEST("name");
	$group = sxREQUEST("group");
	$pu_linked = sxREQUEST("pu_linked");
	$sequence = sxREQUEST("sequence");
	$label = sxREQUEST("label");
	$tooltip = sxREQUEST("tooltip");
	$note = sxREQUEST("note");
}else{
	$process_unit = sxREQ("pu");
	$name = sxREQ("lnk");
	$group = "";
	$pu_linked =  "";
	$sequence =  "";
	$label =  "";
	$tooltip =  "";
	$note =  "";
}
$sSQL = "SELECT * FROM pu_link WHERE process_unit='$process_unit' AND name='$name'";
$objSDAO->query($sSQL,"sel");
if(!$row = $objSDAO->fetch("sel")){
	$url = $_SESSION[USEROBJ]->getHistory(-1, true).
		"&msg=".urlencode(_t("nome link '%s' cambiato",$name));
	serverRedir($url);
}else{
	extract($row,EXTR_OVERWRITE);
}
//output HTML
$aOpz = array("kMenu"=>'pro.pru', "isReloadable"=>$isReloadable);
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript" src="../../_jsc/form.js"></script>   
<?php
echo(bodyHTML($aOpz));

echo("<form name=\"objFrm\" id=\"objFrm\" action=\"puLinkView.php\" method=\"POST\" enctype=\"multipart/form-data\">");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"save\">");
echo("<input type=\"hidden\" name=\"xsn\" value=\"".XSN."\">");
echo("<input type=\"hidden\" name=\"process_unit\" id=\"process_unit\" value=\"$process_unit\">");
echo("<input type=\"hidden\" name=\"name\" id=\"name\" value=\"$name\">");

echo getPuHeader($process_unit);

$aCmd = array(	"mod"=>array("pag"=>"puLinkMod.php?pu=$process_unit&lnk=$name",
										"title"=>_t("change"),
										"text"=>_t("change"),
										"perm"=>"viewmod"),
					"del"=>array("pag"=>"javascript:confirmDelete();",
										"title"=>_t("delete"),
										"text"=>_t("delete"),
										"perm"=>"viewmod"),
					"back"=>array("pag"=>$objUser->getHistory(-1,false),
										"title"=>$objUser->getHistoryText(-1),
										"text"=>$objUser->getHistoryText(-1)
										)
					);
echo(commandsHTML($aCmd));	

echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"titl01\" colspan='2'>Link</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\" width='15%'>Name</td>" .
			"<td class=\"text01\" width='85%'>$name</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Linked process-unit</td>" .
			"<td class=\"text01\">" .
			(($pu_linked=='- back -')?'- previous -':(($pu_linked=='- self -')?'- self -':$pu_linked)).
			"</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Group</td>" .
			"<td class=\"text01\">".sxHE($group)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Sequence</td>" .
			"<td class=\"text01\">".sxHE($sequence)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Label</td>" .
			"<td class=\"text01\">".sxHE($label)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Tool-tip</td>" .
			"<td class=\"text01\"><pre class=\"text01\">".sxWW(sxHE($tooltip))."</pre></td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Note</td>" .
			"<td class=\"text01\"><pre class=\"text01\">".sxWW(sxHE($note))."</pre></td>" .
		"</tr>\n");
echo("</table>");
echo(commandsHTML($aCmd));
echo("</form>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());
exit();

function puLinkDel(){
 	global $objSDAO;
	$quote = "`";
	$errMsg = "";
	$process_unit = addslashes(sxGPC(trim($_REQUEST["process_unit"])));
	$name = addslashes(sxGPC(trim($_REQUEST["name"])));
	$sSQL = "DELETE FROM pu_link " .
				"WHERE process_unit='$process_unit' AND name='$name'";	
	$objSDAO->query($sSQL,"del");
	$url = $_SESSION[USEROBJ]->getHistory(-1, true);
	serverRedir($url);
	return 'abnormal end';
 }
